package com.bcw.springtest.controller;

import com.bcw.springtest.bean.AcmeProperties;
import com.bcw.springtest.bean.MyBean;
import com.bcw.springtest.event.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class Monitor {

    @Resource
    private AcmeProperties acmeProperties;

    @Resource
    private UserService userService;
    @Resource
    private MyBean myBean;
    @Resource
    ApplicationContext applicationContext;

    @RequestMapping(value="monitor",method = RequestMethod.GET)
    public Object monitor(){
        System.out.println(myBean.getAppDesc());
        System.out.println(myBean.getAge());
        System.out.println(myBean.getNumber());
        System.out.println(myBean.getSecret());
        MyBean m = (MyBean) applicationContext.getBean("myBean");
        return m;
//        userService.sendUser();
//        return myBean.getApplicationArguments();
    }


    @RequestMapping(value="post",method = RequestMethod.POST)
    public String post(HttpServletRequest request){
        String name = request.getParameter("name");
        System.out.println(name);
        return name;
    }

    @RequestMapping(value="put/{id}",method = RequestMethod.PUT)
    public Integer put(HttpServletRequest request, @PathVariable("id") Integer id,
                       @RequestParam("name") String name){
        String idStr = request.getParameter("id");
        System.out.println(idStr);
        return id;
    }

    @RequestMapping(value="delete",method = RequestMethod.DELETE)
    public void delete(){
        System.out.println(1);
        return;
    }


}
